<template>
	<view>
		<view class="headForm">
			<u-form :model="formData" ref="uForm" label-width="160">
				<u-form-item label="船名/航次:" label-width="160">
					<u-input type="select" :select-open="shipShow" v-model="formData.ship"
						placeholder="请选择船名/航次" @click="shipShow = true"></u-input>
				</u-form-item> 
			</u-form> 
			<view class="btnGroup">
				<u-button :custom-style="customStyle" type="primary" @click="reset">重置</u-button>  
				<u-button :custom-style="customStyle" type="primary" @click="search">查询</u-button>  
			</view>
		</view>
		<view style="height: 250rpx;"></view>
		<view class="listCon">
			<view class="listItem" v-for="(item, index) in datalist" :key="index">
				<view class="infoCon">
					<view class="container">
						<view class="cellItem">
							<view class="label">
								<view class="title">
									{{ item.cargo }} 提单号：{{ item.loadingbill }} <br/>
								</view>
								车次：{{ item.carcodes }}  总数量：{{ item.number }} 已完成：{{ item.isworks }} 剩余：{{ item.number-item.isworks }}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<u-select mode="single-column" :list="shipList" v-model="shipShow" @confirm="shipConfirm"
			value-name="id" label-name="shipname"  >
		</u-select>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				customStyle: {
					height: '60rpx',
				},
				shipList: [],
				datalist: [],	// 请求list
				shipShow: false,
				nickName: uni.getStorageSync("nickName"),  // username
				formData: {
					ship: '',	// 船名+航次
					shipid: '' // id
				}
			};
		},
		onLoad() {
			this.getOptions()
		},
		methods: {
			getOptions(){
				uni.request({
					url: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/nPVXgmoa742yq6F?username=' + this.nickName,  
					method: 'get',
					success: (res) => {
						this.shipList = res.data.rows
					}
				})
			},
			search() {
				if(this.formData.ship !== '') {
					uni.request({
						url: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/JU9Vi4OW6Kfb5bW',
						method: 'get',
						data: {
							shipid: this.formData.shipid
						},
						success: (res) => {
							this.datalist = res.data.rows
						}
					})
				} else {
					uni.showToast({
						title: '请先选择船名/航次',
						icon: 'none'
					})
				}
			},
			reset() {
				this.formData.ship = ''
				this.formData.shipid = ''
			},
			shipConfirm(e) {
				this.formData.ship = e[0].label
				this.formData.shipid = e[0].value
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-form-item {
		padding: 6rpx !important;
	}
	::v-deep .u-btn {
		height: 20px;
	}
.headForm {
		padding: 20rpx;
		position: fixed;
		width: 100%;
		top: 0;
		z-index: 10;
		background-color: #FFFFFF;

		.btnGroup {
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-top: 45rpx;
		}
	}
	
.listCon {
		.listItem {
			margin-left: 10px;
			padding: 20rpx;
			border-bottom: 1px solid $u-border-color;
			display: flex;
			align-items: center;
			.infoCon {
				width: 90%;
				display: flex;
				align-items: center;
				justify-content: space-between;
	
				.cellItem {
					display: flex;
					align-items: center;
					font-size: 28rpx;
					.label {
						.title{
							font-size: 20px;
							font-weight: 800;
						}
					}
				}		
			}
		}
	}
		
</style>
